﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Xml.Linq;
using System.Windows.Navigation;
using System.ComponentModel;
using Common.Library;
using OnlineVideos.Library;
using OnlineVideos.UI;
using OnlineVideos.Data;
using Common.Utilities;


namespace OnlineVideos.Views
{
    public partial class Help : PhoneApplicationPage
    {
        #region GlobalDeclaration
        string id, url;
        #endregion

        #region Constructor
        public Help()
        {
           
            InitializeComponent();
            id = string.Empty;
            url = string.Empty;
            LoadAds();
            Loaded += new RoutedEventHandler(Help_Loaded);
        }
        #endregion
        #region "Common Methods"

        private void LoadAds()
            {
            try
            {
                PageHelper.LoadAdControl(LayoutRoot, adstackpl, 2);
            }
            catch (Exception ex)
            {
                Exceptions.SaveOrSendExceptions("Exception in LoadAds Method In SongDetails file", ex);
                string excepmess = "Exception in LoadAds Method In SongDetails file.\n\n" + ex.Message + "\n\n StackTrace :- \n" + ex.StackTrace;
            }

     
          
        }
        #endregion
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            try
            {
                FlurryWP8SDK.Api.EndTimedEvent("Help Page");
            }
            catch (Exception ex)
            {

                Exceptions.SaveOrSendExceptions("Exception in OnNavigatedFrom Method In Help.cs file.", ex);
            }
        }
       
        #region PageLoad
        void Help_Loaded(object sender, RoutedEventArgs e)
        {

            try
            {
                FlurryWP8SDK.Api.LogEvent("Help Page", true);
            if (NavigationContext.QueryString.TryGetValue("id", out id))

                if (NavigationContext.QueryString.TryGetValue("url", out url))
                    tblkVideosTitle.Text = OnlineShow.GetHelpItemTitle(id);
            lbxhelp.ItemsSource = OnlineShow.GetHelpItem(id);
        }
            catch (Exception ex)
            {
                
               Exceptions.SaveOrSendExceptions("Exception in Help_Loaded Method In Help.cs file.", ex);
            }
        }
        #endregion

         #region "Common Methods"
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                FlurryWP8SDK.Api.LogPageView();
            }
            catch (Exception ex)
            {

                Exceptions.SaveOrSendExceptions("Exception in OnNavigatedTo Method In Help.cs file.", ex);
            }
            //YouTube.CancelPlay();

        }
        protected override void OnBackKeyPress(CancelEventArgs e)
        {
            //if (YouTube.CancelPlay())
            //    e.Cancel = true;
            //else
            //{

            //}
            SettingsHelper.Save("Repeatads", "1");
            base.OnBackKeyPress(e);
        }
        
      
        #endregion

        #region Events
        private void imgTitle_MouseEnter(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Navigate(NavigationHelper.MainPanoramaPage);
        }
        private void ApplicationBarIconButton_youtube_Click(object sender, EventArgs e)
        {
          
           //YouTube.LoadYoutubeVideo(url);
            try
            {
              
               NavigationService.Navigate(new Uri("/Views/Youtube.xaml?myid=" + url, UriKind.Relative));
            //YoutubeApi.Youtube.PlayYoutubeVideo(url);
        }
            catch (Exception ex)
            {
                
                Exceptions.SaveOrSendExceptions("Exception in ApplicationBarIconButton_youtube_Click Method In Help.cs file.", ex);
            }
        }
        #endregion
    }
}